<?php
declare (strict_types = 1);
namespace app\admin\model\data;

use app\user\logic\user\Account;

/**
 * 学员-会员开通情况
 */
class StudentVip extends DataModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'user_vip';
    /**
     * 购买者
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-04
     * @return   [type]                         [description]
     */
    public function user()
    {
        return $this->belongsTo(Account::class, 'user_id');
    }
    /**
     * 获取某个时间段的会员数
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-21
     * @param    array                          $timespan [description]
     * @return   [type]                                   [description]
     */
    public static function getVipUserCountByTimespan(array $timespan)
    {
        return StudentVip::scope('mhm', 'user.mhm_id')->withJoin(['user' => ['mhm_id']])->whereBetween('__TABLE__.create_time', $timespan)->count();
    }
}
